tag = document.getElementsByClassName("issue-wrapper")
parent = document.getElementById("git-issues")
let open_frame = null

function open_link(e) {
    let url = e.getElementsByClassName("title")[0].href;
    let child = document.createElement("iframe");
    child.src = url;
    child.style.width = "-webkit-fill-available"
    child.style.height = "800px"
    parent.insertBefore(child, e.nextSibling);
    open_frame = child
}

function close_link() {
    parent.removeChild(open_frame)
    open_frame = null
}

function addBtn() {
    for (let i = 0; i < tag.length; i++) {
        let btn = document.createElement("button");
        btn.innerHTML = "Open";
        btn.onclick = function () {
            if (open_frame) {
                close_link()
                open_link(tag[i])
            } else {
                open_link(tag[i])
            }
        }
        tag[i].appendChild(btn);
    }
}
addBtn();